package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.ApartmentInfo;
import com.atguigu.lease.web.admin.mapper.ApartmentInfoMapper;
import com.atguigu.lease.web.admin.service.ApartmentInfoService;
import com.atguigu.lease.web.admin.vo.apartment.ApartmentItemVo;
import com.atguigu.lease.web.admin.vo.apartment.ApartmentQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
        implements ApartmentInfoService {

    @Override
    public IPage<ApartmentItemVo> pageItem(Page<ApartmentItemVo> page , ApartmentQueryVo queryVo) {

        // 匹配地址，查询的时候，是   ApartmentInfo 逐步进行地址匹配，还要考虑是否为空

        /*LambdaQueryWrapper<ApartmentInfo> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.eq(queryVo.getProvinceId()!=null,ApartmentInfo::getProvinceId,queryVo.getProvinceId())
                .eq(queryVo.getCityId()!=null,ApartmentInfo::getCityId,queryVo.getCityId())
                .eq(queryVo.getDistrictId()!=null,ApartmentInfo::getDistrictId,queryVo.getDistrictId());*/


        // Page<ApartmentItemVo>  apartmentItemVoPage =  baseMapper.selectPage(page,queryWrapper);
        // 报错分析，自带的 selectPage 方法 返回值为 P ，说明 queryWrapper 进行的是单表查询，而我们要的是多表查询的结果，所以需要自己去写一个方法
        // 自己写方法之后，上面的地址匹配代码即可被注释掉，已经不需要 queryWrapper 参数


        IPage<ApartmentItemVo>  apartmentItemVoPage =  baseMapper.selectApartmentItemVoPage(page,queryVo);




        return apartmentItemVoPage;
    }
}




